//Design By Do Trung --- Email : trungqn19852003@yahoo.com
//Ngày Design :5/4/2011 5:00:13 PM
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using System.Collections.Generic;
 
	/// <summary>
	/// </summary>
	public class TaiNguyen_DA
	{
		public TaiNguyen_DA() {}
#region 'Variables And Properties'
		 private int int_IdTaiNguyen ;
		 public int IdTaiNguyen
			{
			 get 	
				{
					 return this.int_IdTaiNguyen;
				}
			 set 	
				{
					int_IdTaiNguyen=value;
				}
			}
		 private int int_IdChuyenMuc ;
		 public int IdChuyenMuc
			{
			 get 	
				{
					 return this.int_IdChuyenMuc;
				}
			 set 	
				{
					int_IdChuyenMuc=value;
				}
			}
		 private int int_IdThuVien ;
		 public int IdThuVien
			{
			 get 	
				{
					 return this.int_IdThuVien;
				}
			 set 	
				{
					int_IdThuVien=value;
				}
			}
		 private string string_TenDangNhap ;
		 public string TenDangNhap
			{
			 get 	
				{
					 return this.string_TenDangNhap;
				}
			 set 	
				{
					string_TenDangNhap=value;
				}
			}
		 private string string_TenTapTin ;
		 public string TenTapTin
			{
			 get 	
				{
					 return this.string_TenTapTin;
				}
			 set 	
				{
					string_TenTapTin=value;
				}
			}
		 private string string_DuongDanTapTin ;
		 public string DuongDanTapTin
			{
			 get 	
				{
					 return this.string_DuongDanTapTin;
				}
			 set 	
				{
					string_DuongDanTapTin=value;
				}
			}
		 private string string_DungLuongTapTin ;
		 public string DungLuongTapTin
			{
			 get 	
				{
					 return this.string_DungLuongTapTin;
				}
			 set 	
				{
					string_DungLuongTapTin=value;
				}
			}
		 private string string_MoTaTapTin ;
		 public string MoTaTapTin
			{
			 get 	
				{
					 return this.string_MoTaTapTin;
				}
			 set 	
				{
					string_MoTaTapTin=value;
				}
			}
		 private string string_HinhAnhMoTa ;
		 public string HinhAnhMoTa
			{
			 get 	
				{
					 return this.string_HinhAnhMoTa;
				}
			 set 	
				{
					string_HinhAnhMoTa=value;
				}
			}
		 private string string_SoLuotTaiVe ;
		 public string SoLuotTaiVe
			{
			 get 	
				{
					 return this.string_SoLuotTaiVe;
				}
			 set 	
				{
					string_SoLuotTaiVe=value;
				}
			}
		 private bool bool_TrangThai ;
		 public bool TrangThai
			{
			 get 	
				{
					 return this.bool_TrangThai;
				}
			 set 	
				{
					bool_TrangThai=value;
				}
			}
#endregion

		/// <summary>
		/// Inserts a record into the TaiNguyen table.
		/// <summary>
		/// <param name="IdTaiNguyen"></param>
		/// <param name="IdChuyenMuc"></param>
		/// <param name="IdThuVien"></param>
		/// <param name="TenDangNhap"></param>
		/// <param name="TenTapTin"></param>
		/// <param name="DuongDanTapTin"></param>
		/// <param name="DungLuongTapTin"></param>
		/// <param name="MoTaTapTin"></param>
		/// <param name="HinhAnhMoTa"></param>
		/// <param name="SoLuotTaiVe"></param>
		/// <param name="TrangThai"></param>
		/// <returns></returns>
		public bool Insert(SqlConnection SqlCnn)
		{
			bool boolInsert = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TaiNguyen_Insert";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTaiNguyen", SqlDbType.Int).Value=IdTaiNguyen;
			SqlCmd.Parameters.Add("@IdChuyenMuc", SqlDbType.Int).Value=IdChuyenMuc;
			SqlCmd.Parameters.Add("@IdThuVien", SqlDbType.Int).Value=IdThuVien;
			SqlCmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar,50).Value=TenDangNhap;
			SqlCmd.Parameters.Add("@TenTapTin", SqlDbType.NVarChar,50).Value=TenTapTin;
			SqlCmd.Parameters.Add("@DuongDanTapTin", SqlDbType.NVarChar,250).Value=DuongDanTapTin;
			SqlCmd.Parameters.Add("@DungLuongTapTin", SqlDbType.NVarChar,10).Value=DungLuongTapTin;
			SqlCmd.Parameters.Add("@MoTaTapTin", SqlDbType.NChar,10).Value=MoTaTapTin;
			SqlCmd.Parameters.Add("@HinhAnhMoTa", SqlDbType.NVarChar,250).Value=HinhAnhMoTa;
			SqlCmd.Parameters.Add("@SoLuotTaiVe", SqlDbType.NChar,10).Value=SoLuotTaiVe;
			SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value=TrangThai;

			SqlAdp.InsertCommand = SqlCmd;
			SqlAdp.InsertCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolInsert = true;
			}
			catch
			{
			boolInsert = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolInsert;
		}

		/// <summary>
		/// Selects a single record from the TaiNguyen table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable Select(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TaiNguyen_Select";
			SqlCmd.CommandType=CommandType.StoredProcedure;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
		}

		/// <summary>
		/// Selects a single record from the TaiNguyen table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable SelectPrimaryKey(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TaiNguyen_SelectPrimaryKey";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTaiNguyen", SqlDbType.Int).Value=IdTaiNguyen;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
			}

		/// <summary>
		/// Updates a record in the TaiNguyen table.
		/// <summary>
		/// <param name="IdTaiNguyen"></param>
		/// <param name="IdChuyenMuc"></param>
		/// <param name="IdThuVien"></param>
		/// <param name="TenDangNhap"></param>
		/// <param name="TenTapTin"></param>
		/// <param name="DuongDanTapTin"></param>
		/// <param name="DungLuongTapTin"></param>
		/// <param name="MoTaTapTin"></param>
		/// <param name="HinhAnhMoTa"></param>
		/// <param name="SoLuotTaiVe"></param>
		/// <param name="TrangThai"></param>
		public bool Update(SqlConnection SqlCnn)
		{
			bool boolUpdate = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TaiNguyen_Update";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTaiNguyen", SqlDbType.Int).Value=IdTaiNguyen;
			SqlCmd.Parameters.Add("@IdChuyenMuc", SqlDbType.Int).Value=IdChuyenMuc;
			SqlCmd.Parameters.Add("@IdThuVien", SqlDbType.Int).Value=IdThuVien;
			SqlCmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar,50).Value=TenDangNhap;
			SqlCmd.Parameters.Add("@TenTapTin", SqlDbType.NVarChar,50).Value=TenTapTin;
			SqlCmd.Parameters.Add("@DuongDanTapTin", SqlDbType.NVarChar,250).Value=DuongDanTapTin;
			SqlCmd.Parameters.Add("@DungLuongTapTin", SqlDbType.NVarChar,10).Value=DungLuongTapTin;
			SqlCmd.Parameters.Add("@MoTaTapTin", SqlDbType.NChar,10).Value=MoTaTapTin;
			SqlCmd.Parameters.Add("@HinhAnhMoTa", SqlDbType.NVarChar,250).Value=HinhAnhMoTa;
			SqlCmd.Parameters.Add("@SoLuotTaiVe", SqlDbType.NChar,10).Value=SoLuotTaiVe;
            SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value = TrangThai;

			SqlAdp.UpdateCommand = SqlCmd;
			SqlAdp.UpdateCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolUpdate = true ;
			}
			catch
			{
			boolUpdate = false ;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolUpdate;
		}

		/// <summary>
		/// Deletes a record from the TaiNguyen table by a composite primary key.
		/// <summary>
		public bool Delete(SqlConnection SqlCnn)
		{
			bool boolDelete = false;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TaiNguyen_Delete";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTaiNguyen", SqlDbType.Int).Value=IdTaiNguyen;

			SqlAdp.DeleteCommand = SqlCmd;
			SqlAdp.DeleteCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolDelete = true;
			}
			catch
			{
                boolDelete = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolDelete;
			}
	}
 
